﻿using Microsoft.EntityFrameworkCore;
using SanJ.FreeCare.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;

namespace SanJ.FreeCare.AllergyIntolerances
{
    public class EfCoreAllergyIntoleranceDefinitionRepository
              : EfCoreRepository<FreeCareDbContext, AllergyIntolerance, Guid>,
                 IAllergyIntoleranceResponstiry
    {
        public EfCoreAllergyIntoleranceDefinitionRepository(IDbContextProvider<FreeCareDbContext> dbContextProvider) : base(dbContextProvider)
        {

        }

        /// <summary>
        /// 根据患者patientId号查询过敏不耐受记录
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public async Task<AllergyIntolerance> GetAllergyIntoleranceRecordByPatientIdAsync(Guid patientId)
        {
            var dbSet = await GetDbSetAsync();

            return await dbSet.AsNoTracking().Where(t => t.PatientId == patientId).FirstAsync();

        }

        /// <summary>
        /// 根据患者EncounterId号查询过敏不耐受记录
        /// </summary>
        /// <param name="encounterId"></param>
        /// <returns></returns>
        public async Task<AllergyIntolerance> GetAllergyIntoleranceRecordByEncounterIdAsync(Guid encounterId)
        {
            var dbSet = await GetDbSetAsync();
            return await dbSet.AsNoTracking().Where(t => t.EncounterId == encounterId).FirstAsync();
        }
    }
}
